
***********************************************************
*** ELECTIONS AND SOCIAL CONFLICT - Revise and Resubmit analysis for SCID, Jan. 2014
***********************************************************





use "C:\Users\Chris\Dropbox\ISA 2012\AFRICA-ELECTION-CONFLICT_COUNTRY-MONTHS-vJan2014.dta", clear



*XT set the data
gen day = 1
gen time = mdy(month, day, year)
xtset ccode time

*Generate new variables
gen lnpop =ln(pop)
gen lngdp = ln(rgdpch)
gen democracy = 0
replace democracy = 1 if polity2>=6
gen electcw = election*civwar
gen elect_democracy = election*democracy
gen elect_polity = election*polity2
gen elect_postcw24 = election*postwar_24
gen elect_postcw12 = election*postwar_12
gen elect_postcw6 = election*postwar_6
gen elect_postcw18 = election*postwar_18
gen elect_gdp = election*lngdp

*generate alternate versions of democracy (NEW CODE)
gen democracy5 = 0
replace democracy5 = 1 if polity2>=5
gen democracy0 = 0
replace democracy0 = 1 if polity2>=0

*generate postwar election count variables (NEW CODE)
gen firstpostwarelection=0
replace firstpostwarelection=1 if postwar_electioncount==1

gen secondpostwarelection=0
replace secondpostwarelection=1 if postwar_electioncount==2
 
*generate noncompetitive elections (NEW CODE)
gen noncompete_election=0
replace noncompete_election = 1 if competitive_elect==0

*generate first and second competitive elections (NEW CODE)
gen first_compete_elect = 0
replace first_compete_elect =1 if (competitive_elect==1 & firstpostwarelection==1)

gen second_compete_elect = 0
replace second_compete_elect =1 if (competitive_elect==1 & secondpostwarelection==1)




*generate lags
gen lagDV1 = scad_total[_n-1]
gen lagDV2 = scad_total[_n-2]
gen lagDV3 = scad_total[_n-3]
gen lagDV4 = scad_total[_n-4]
gen lagDV5 = scad_total[_n-5]
gen lagDV6 = scad_total[_n-6]

*generate lage of violent events
gen lagve1 = violent_event[_n-1]
gen lagve2 = violent_event[_n-2]
gen lagve3 = violent_event[_n-3]
gen lagve4 = violent_event[_n-4]
gen lagve5 = violent_event[_n-5]
gen lagve6 = violent_event[_n-6]

*cut and paste this into models lagDV1 lagDV2 lagDV3 lagDV4 lagDV5 lagDV6 

*lags of deaths
gen lagdeath1 = ndeath[_n-1]
gen lagdeath2 = ndeath[_n-2]
gen lagdeath3 = ndeath[_n-3]
gen lagdeath4 = ndeath[_n-4]
gen lagdeath5 = ndeath[_n-5]
gen lagdeath6 = ndeath[_n-6]

*cut and paste lagdeath1 lagdeath2 lagdeath3 lagdeath4 lagdeath5 lagdeath6 

*Generate election period variables

gen ep1 = 0
replace ep1 = 1 if election == 1
replace ep1 = 1 if pre_election == 1
replace ep1 = 1 if post_election == 1

gen ep3 = 0
replace ep3 = 1 if election == 1
replace ep3 = 1 if pre_election == 1
replace ep3 = 1 if pre_election == 2
replace ep3 = 1 if pre_election == 3
replace ep3 = 1 if post_election == 1
replace ep3 = 1 if post_election == 2
replace ep3 = 1 if post_election == 3


gen ep6 = 0
replace ep6 = 1 if election == 1
replace ep6 = 1 if pre_election == 1
replace ep6 = 1 if pre_election == 2
replace ep6 = 1 if pre_election == 3
replace ep6 = 1 if pre_election == 4
replace ep6 = 1 if pre_election == 5
replace ep6 = 1 if pre_election == 6

replace ep6 = 1 if post_election == 1
replace ep6 = 1 if post_election == 2
replace ep6 = 1 if post_election == 3
replace ep6 = 1 if post_election == 4
replace ep6 = 1 if post_election == 5
replace ep6 = 1 if post_election == 6

*Gen pre and post month variables
gen month_prior = 0
replace month_prior = 1 if pre_election == 1
gen month_after = 0
replace month_after = 1 if post_election ==1




******************************************************
****TABLE 1  BASIC ANALYSIS***
******************************************************
***TABLE 1***

*MODELS 1-3: Basic model.  Number of events, violent events, and deaths
*Controls (lags, civil war incidence, post war, polity, population, gdp, elf, media coverage)
set more off
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab1" , eform cti(irr) excel replace
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab1" , eform cti(irr) excel 
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab1" , eform cti(irr) excel 

	*(Robustness only).  Include 1 month pre/post election period -- Number of events and deaths 
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr

	*(Robustness only).  3month election periods.
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr

	*(Robustness only). 6 month postwar period  (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr

	*(Robustness only). 18 month postwar period  (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr



*Models 3-6.  Disaggregate pre and post election months -- Number of events and deaths
set more off
xtnbreg scad_total lagDV1 lagDV2 lagDV3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab1" , eform cti(irr) excel 
xtnbreg violent_event lagve1 lagve2 lagve3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab1" , eform cti(irr) excel 
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab1" , eform cti(irr) excel 

	
	*(Robustness only). 6 month postwar period (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 month_prior election month_after civwar postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 month_prior election month_after civwar postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 month_prior election month_after civwar postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr

	
	*(Robustness only). 18 month postwar period (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 month_prior election month_after civwar postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 month_prior election month_after civwar postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 month_prior election month_after civwar postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr



******************************************************
****TABLE 2  INTERACTION TERMS***
******************************************************
***TABLE 2***

*Models 7-9.  Interaction with current civil war
set more off
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election  civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	**outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel replace
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	**outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr
	**outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 

	*robustness only. 6 month post war period (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election  civwar electcw postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar electcw postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar electcw postwar_6 democracy  lnpop lngdp elf media_quartiles, re irr

	
	*robustness only. 18 month post war period (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election  civwar electcw postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar electcw postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar electcw postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr

	*robustness only. 18 month post war period (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election  civwar electcw postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar electcw postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar electcw postwar_18 democracy  lnpop lngdp elf media_quartiles, re irr

	
	
	
	
*Models 10-13.  Interaction with post civil war (12month) period
set more off
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 

	*(Robustness only).  Interaction with post civil war (6month) (NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_6 elect_postcw6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_6 elect_postcw6 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_6 elect_postcw6 democracy  lnpop lngdp elf media_quartiles, re irr
	
	*(Robustness only).  Interaction with post civil war (18month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_18 elect_postcw18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_18 elect_postcw18 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_18 elect_postcw18 democracy  lnpop lngdp elf media_quartiles, re irr
	
	*(Robustness only).  Interaction with post civil war (24month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, re irr
	
	
	
	

*Models 13-15.  Interaction with democracy
set more off
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy elect_democracy lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 

	
	*(Robustness only).  Interaction with post civil war (6month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_6 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_6 democracy elect_democracy lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_6 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr

		
	*(Robustness only).  Interaction with post civil war (18month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_18 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_18 democracy elect_democracy lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_18 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr

		
	*(Robustness only).  Interaction with post civil war (24month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_24 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_24 democracy elect_democracy lnpop lngdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_24 democracy elect_democracy  lnpop lngdp elf media_quartiles, re irr

	
	
	
	
*Models 16-18.  Interaction with gdp
set more off
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab2" , eform cti(irr) excel 

	*(Robustness only).  Interaction with post civil war (6month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_6 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_6 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_6 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	
	*(Robustness only).  Interaction with post civil war (18month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_18 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_18 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_18 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	
	*(Robustness only).  Interaction with post civil war (24month)(NEW CODE)
	xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_24 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_24 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr
	xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_24 democracy  lnpop lngdp elect_gdp elf media_quartiles, re irr

	
	
	

*******************
*ROBUSTNESS CHECKS*
*******************



*(Robustness).  Political & non-political events
*gen lag1_pole = political_event[_n-1]
*gen lag2_pole = political_event[_n-2]
*gen lag3_pole = political_event[_n-3]
xtnbreg political_event lag1_pole lag2_pole lag3_pole election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr

*gen lag1_npole = non_political_event[_n-1]
*gen lag2_npole = non_political_event[_n-2]
*gen lag3_npole = non_political_event[_n-3]
xtnbreg non_political_event lag1_npole lag2_npole lag3_npole election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, re irr

*ROBUSTNESS: RUN MODELS WITH NBREG, CLUSTER CCODE
***TABLE 1***
*MODELS 1-3: Basic model.  Number of events, violent events, and deaths
*Controls (lags, civil war incidence, post war, polity, population, gdp, elf, media coverage)
nbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr


*(Robustness only).  Include 1 month pre/post election period -- Number of events and deaths
nbreg scad_total lagDV1 lagDV2 lagDV3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr

*(Robustness only).  3month election periods.
nbreg scad_total lagDV1 lagDV2 lagDV3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr

*Models 3-6.  Disaggregate pre and post election months -- Number of events and deaths
nbreg scad_total lagDV1 lagDV2 lagDV3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr


***TABLE 2***
*Models 7-9.  Interaction with current civil war
nbreg scad_total lagDV1 lagDV2 lagDV3 election  civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr


*Models 10-13.  Interaction with post civil war (12month) period
nbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr

*(Robustness only).  Interaction with post civil war (24month)
nbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr

*Models 13-15.  Interaction with democracy
nbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy elect_democracy lnpop lngdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles, cluster(ccode) irr

*Models 16-19.  Interaction with gdp
nbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, cluster(ccode) irr
nbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, cluster(ccode) irr
nbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, cluster(ccode) irr



*ROBUSTNESS: USE FIXED EFFECTS
***TABLE 1***
*MODELS 1-3: Basic model.  Number of events, violent events, and deaths
*Controls (lags, civil war incidence, post war, polity, population, gdp, elf, media coverage)
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr

*(Robustness only).  Include 1 month pre/post election period -- Number of events and deaths
xtnbreg scad_total lagDV1 lagDV2 lagDV3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr

*(Robustness only).  3month election periods.
xtnbreg scad_total lagDV1 lagDV2 lagDV3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr

*Models 3-6.  Disaggregate pre and post election months -- Number of events and deaths
xtnbreg scad_total lagDV1 lagDV2 lagDV3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr

***TABLE 2***
*Models 7-9.  Interaction with current civil war
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election  civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles, fe irr

*Models 10-13.  Interaction with post civil war (12month) period
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles, fe irr

*(Robustness only).  Interaction with post civil war (24month)
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles, fe irr

*Models 13-15.  Interaction with democracy
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy elect_democracy lnpop lngdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles, fe irr

*Models 16-19.  Interaction with gdp
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, fe irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, fe irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles, fe irr


***EXCLUDE KENYA 2007****
***TABLE 1***
*MODELS 1-3: Basic model.  Number of events, violent events, and deaths
*Controls (lags, civil war incidence, post war, polity, population, gdp, elf, media coverage)
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

*(Robustness only).  Include 1 month pre/post election period -- Number of events and deaths
xtnbreg scad_total lagDV1 lagDV2 lagDV3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep1 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

*(Robustness only).  3month election periods.
xtnbreg scad_total lagDV1 lagDV2 lagDV3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 ep3 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

*Models 3-6.  Disaggregate pre and post election months -- Number of events and deaths
xtnbreg scad_total lagDV1 lagDV2 lagDV3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 month_prior election month_after civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

***TABLE 2***
*Models 7-9.  Interaction with current civil war
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election  civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar electcw postwar_12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

*Models 10-13.  Interaction with post civil war (12month) period
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 elect_postcw12 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

*(Robustness only).  Interaction with post civil war (24month)
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_24 elect_postcw24 democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

*Models 13-15.  Interaction with democracy
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy elect_democracy lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy elect_democracy  lnpop lngdp elf media_quartiles if kenya_dummy !=1, re irr

*Models 16-19.  Interaction with gdp
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles if kenya_dummy !=1, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy  lnpop lngdp elect_gdp elf media_quartiles if kenya_dummy !=1, re irr





******************************************************
****TABLE 3  WITH NELDA INDEPENDENT VARIABLES***
******************************************************
set more off

****  ELECTION PERIODS (MODELS 1-3)***
nbreg scad_total victory_margin month_prior month_after nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if ep1==1, cluster(ccode) irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab3" , eform cti(irr) excel replace
nbreg violent_event victory_margin month_prior month_after nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if ep1==1, cluster(ccode) irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab3" , eform cti(irr) excel 
nbreg ndeath victory_margin month_prior month_after nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if ep1==1, cluster(ccode) irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab3" , eform cti(irr) excel 


****  ELECTION MONTHS ONLY (MODELS 4-6)***
nbreg scad_total  victory_margin nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if election==1, cluster(ccode) irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab3" , eform cti(irr) excel 
nbreg violent_event  victory_margin nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if election==1, cluster(ccode) irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab3" , eform cti(irr) excel 
nbreg ndeath  victory_margin nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if election==1, cluster(ccode) irr
	*outreg2 using "C:\Users\Chris\Desktop\Results\scid-tab3" , eform cti(irr) excel 

	
*****************************************************
**ROBUSTNESS CHECKS - ALTERNATIVE DEMOCRACY THRESHOLDS
******************************************************
xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy0  lnpop lngdp elf media_quartiles, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy0  lnpop lngdp elf media_quartiles, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy0  lnpop lngdp elf media_quartiles, re irr

gen elect_democracy0 = election*democracy0

xtnbreg scad_total lagDV1 lagDV2 lagDV3 election civwar postwar_12 democracy elect_democracy0  lnpop lngdp elf media_quartiles, re irr
xtnbreg violent_event lagve1 lagve2 lagve3 election civwar postwar_12 democracy elect_democracy0 lnpop lngdp elf media_quartiles, re irr
xtnbreg ndeath lagdeath1 lagdeath2 lagdeath3 election civwar postwar_12 democracy elect_democracy0  lnpop lngdp elf media_quartiles, re irr

*****************************************************
**ROBUSTNESS CHECKS - First elections
******************************************************
nbreg scad_total victory_margin month_prior month_after first_compete second_compete nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if ep1==1, cluster(ccode) irr
nbreg violent_event victory_margin month_prior month_after first_compete second_compete nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if ep1==1, cluster(ccode) irr
nbreg ndeath victory_margin month_prior month_after first_compete second_compete nelda45 nelda11 nelda13 nelda15 civwar postwar_12 democracy  lnpop lngdp elf media_quartiles if ep1==1, cluster(ccode) irr

	
*MARGINSPLOT COMMANDS	
*margins, at((mean) _all nelda45=0 nelda11=0 nelda13=0 nelda15=0 civwar=0 postwar_12=0 democracy=0 victory_margin =(.33(20)100))  vsquish
	
	
	